var dangqian = '4';
var nowpage = 1
var form1 = {
    size: 10,
    page: 1,
}
var form2 = {
    total: 2000,
    pageSize: 10,
    showTotal: true,
    showTo: true,
    change: function ( i ) {
        createContent( i );
    }
}
var $content = $( ".content" );
function createContent (i) {
    form1.page = i
    getMessagedata(form1)
}
function changeinfo(id,value){
    form1[id] = value
    // console.log(form1)
}

Helper.ui.page("#page-3", form2);

function getMessagedata(form1){
    $.ajax({
        url:initObj.url + "/api/role/findAllMessage/"+form1.page+"/"+form1.size,
        // data:JSON.stringify(form1),
        // data:form1,
        datatype:'json',
        type:'get',
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        //    console.log(form.token)
        },
        success:function(res){
            console.log(res)
            document.getElementById('selectAll').innerHTML = ""
            for(var i=0;i<res.data.content.length;i++){
                // var isRead = (res.data.content[i].isRead=='未读'?1:0)
                document.getElementById('selectAll').innerHTML += 
                "<li><span style='width:10vw;display:inline-block;overflow: hidden;height:2.8vh'>"+res.data.content[i].title+
                "</span><span style='width:15vw;display:inline-block;overflow: hidden;height:2.8vh'>"+res.data.content[i].content+
                "</span><span style='width:15vw;display:inline-block'>"+res.data.content[i].createTime+
                "</span><button style='color:#f6f6f6;background-color:#ccc;border-radius:15px;display:inline-block;margin-left:5vw' onclick='showDetail("+
                res.data.content[i].id+")'>查看内容</button><span class='isRead' style='width:15vw;display:inline-block'>"+res.data.content[i].isRead+"</span></li>"
                if(res.data.content[i].isRead == '已读'){
                    document.getElementsByClassName('isRead')[i].style.color = "#15b68f"
                }
            }
            if(form2.total !== res.data.totalElements){
                form2.total = res.data.totalElements
                Helper.ui.page("#page-3", form2);
                nowpage++
            }
        }
    })
}
function showDetail(id){
    $.ajax({
        url:initObj.url + "/api/role/updateStauts/"+id,
        // data:JSON.stringify(form1),
        // data:form1,
        datatype:'json',
        type:'put',
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        //    console.log(form.token)
        },
        success:function(res){
            // console.log(res)
            $('#message_content').html(res.data.content)
            $('#message_createTime').html(res.data.createTime)
            $('#message_title').html(res.data.title)
        }
    })
    document.getElementById('message_detail').style.display = "block"
}
function message_close(){
    getMessagedata(form1)
    document.getElementById('message_detail').style.display = "none"
}
getMessagedata(form1)